package com.clean.cleantotal.base

import android.animation.ValueAnimator
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.gyf.immersionbar.ImmersionBar

abstract class BaseActivity<T : ViewBinding> : AppCompatActivity() {
    lateinit var mBinding: T

    protected var animal: ValueAnimator? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = viewBinding
        setContentView(mBinding.root)
        ImmersionBar.with(this).statusBarDarkFont(true).fullScreen(false).init()
        initParams(intent.extras)
        initView()
    }

    protected abstract val viewBinding: T
    abstract fun initView()

    protected fun openActivity(activity: Class<*>?, bundle: Bundle? = null) {
        bundle?.let {
            startActivity(Intent(this, activity).apply { putExtras(it) })
        } ?: kotlin.run {
            startActivity(Intent(this, activity))
        }
    }

    open fun initParams(extras: Bundle?) {

    }

    fun toBack(view: View?) {
        finish()
        this.setResult(0x11)
    }
}
